<script type="text/javascript">
$(function () {
	var pg = App.sequence.infoEdit.ui, pp = pg.params,
		sequenceName = pg.children('.navi').seek('title');
	var frm= {
		catalog:pg.seek('catalog'),
		code:pg.seek('code'),
		name:pg.seek('name'),
		beginNo:pg.seek('beginNo'),
		endNo:pg.seek('endNo'),
		currentNo:pg.seek('currentNo'),
		segLen:pg.seek('segLen'),
		memo:pg.seek('memo'),
		type: pg.seek('type')
	};
	function setValues(o){
		pg.params.id=o.id;
		frm.catalog.val(o.catalog);
		frm.code.val(o.code);
		frm.name.val(o.name);
		frm.beginNo.val(o.beginNo);
		frm.endNo.val(o.endNo);
		frm.currentNo.val(o.currentNo);
		frm.segLen.val(o.segLen);
		frm.memo.val(o.memo);
		frm.type.val(o.type);
	}
	function getValues(){
		return {
			id: pg.params.id,
			catalog: frm.catalog.val(),
			code: frm.code.val(),
			name: frm.name.val(),
			begin: frm.beginNo.val()*1,
			end: frm.endNo.val()*1,
			//currentNo: frm.currentNo.val(),
			segLen: frm.segLen.val()*1,
			memo:frm.memo.val(),
			type:frm.type.selected[0]
		};
	}

	//验证方法
	function validate1(p){
		var x2 = App.validate2, v = App.sequence.validator, m = pg.find('.msg').html('');

		var vd = true
			&& x2(v.svc.cn, frm.catalog)
			&& x2(v.svc.cn, frm.code)
			&& x2(v.svc.name, frm.name)
			&& x2(v.svc.numberBig, frm.beginNo)
			&& x2(v.svc.numberBig, frm.endNo)
			//&& x2(v.svc.numberBig, frm.currentNo)
			&& x2(v.svc.number, frm.segLen)
			&& x2(v.svc.memo, frm.memo)
			&& x2(v.svc.numberTiny, frm.type)
		return vd;
	}

	//失去焦点判断
	pg.find('input').blur(function(e){
		var pms = getValues();
		if(e.currentTarget.name === 'endNo')
			frm.segLen.val((pms.end+'').length);
		if(!validate1(pms,e.currentTarget.name))
			return;


	});

	frm.type.mac('combo', {
		keyField: 'k',
		displayField: 'v',
		multiSelect: false,
		width: 324,
		boxWidth: 324,
		cols : [{
			field: 'v', width: 324
		}],
		data: [{ k: 0, v: '分段序列' },{ k: 1, v: '模式序列' }]
	});
	pg.seek('back').click(function(){
		App.show({
			title: '序列管理',
			ctx: 'sequence',
			action: 'infoIndex',
			params: {}
		}, $.noop, pg.parent());
	});


	//提交
	pg.seek('ok').click(function(){
		var pms = getValues();
		if(!validate1(pms))//触发验证
			return;
		if(pms.begin>=pms.end){
			mac.alert('序列开始值应小于序列结束值~');
			return;
		}
		if(pms.segLen>pms.end.length){
			mac.alert('长度应小于结束值长度~');
			return;
		}
		$.post(App.ctx + '/info/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				App.show({
					ctx : 'sequence',
					action : 'infoIndex',
					params : {}
				}, $.noop, pg.parent());
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	//修改
	if (pg.params.id) {
		sequenceName.text(pp.name+"序列修改");
		setValues(pg.params);
	}else{
		sequenceName.text("添加序列");
	}



});
</script>
<div class="navi">
	<span class="a" name="back">序列管理</span>&gt;&gt;
	<span name="title">XX序列</span>
</div>
<div class="form">
	<div class="item">
		<span class="label">所属系统：</span>
		<input class="input" type="text" name="catalog" placeholder="请填入所属系统" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">编号：</span>
		<input class="input" type="text" name="code" placeholder="请填入序列编号" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">名称：</span>
		<input class="input" type="text" name="name" placeholder="请填入序列名称" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">起始值：</span>
		<input class="input" min="1" type="number" name="beginNo" placeholder="请填入序列起始值" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">结束值：</span>
		<input class="input" min="1" type="number" name="endNo" placeholder="请填入序列结束值" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
   <!-- <div class="item">
		<span class="label">序列当前值：</span>
		<input class="input" min="1" type="number" name="currentNo" placeholder="请填入序列当前值" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>-->
	<div class="item">
		<span class="label">长度：</span>
		<input class="input" type="number" name="segLen" placeholder="请填入序列长度" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">类型：</span> <div class="combo fl" name="type" ></div>
		<span name="msg" class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">备注：</span>
		<textarea class="input" type="text" name="memo" placeholder="请填入备注" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>

	<div class="bottom">
		<button name="ok" class="addBtn">提交</button>
	</div>
</div>